import { ITab, ITabParams } from '@/interface/tab';
import * as request from './request';

export async function getAllTab(body: ITabParams) {
  try {
    const login = sessionStorage.getItem('login')?.toString();
    if (login === '1') {
      const data = request.post(JSON.stringify(body), '/api/console/tab/get');
      return data;
    } else {
      return {};
    }
  } catch (e) {
    return e;
  }
}

export async function AddNewTab(body: ITab) {
  try {
    const data = request.post(JSON.stringify(body), '/api/console/tab/add');
    return data;
  } catch (e) {
    return e;
  }
}

export async function changeStateTab(body: ITab) {
  try {
    const data = request.post(
      JSON.stringify(body),
      '/api/console/tab/changeState',
    );
    return data;
  } catch (e) {
    return e;
  }
}

export async function changeValueTab(body: ITab) {
  try {
    const data = request.post(
      JSON.stringify(body),
      '/api/console/tab/editValue',
    );
    return data;
  } catch (e) {
    return e;
  }
}

export async function deleteTab(body: ITab) {
  try {
    const data = request.post(JSON.stringify(body), '/api/console/tab/delete');
    return data;
  } catch (e) {
    return e;
  }
}
